package Add_N;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

// map阶段
// KEYIN: 输入数据的key的类型
// VALUEIN: 输入数据的value的类型
// KEYOUT: 输出数据的key的类型
// VALUEOUT: 输出数据的value的类型
public class AddMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {

    private Text keyOut = new Text();


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();

        String[] words = line.split(",");

        int [] num=new int[15];
        int sum = 0;

        try {
            for(int i = 0; i <= 14; i++){
                num[i] = Integer.valueOf(words[32+i]);
                sum = sum + num[i];
            }
        } catch (NumberFormatException e) {
            return;
        }

        context.write(new IntWritable(sum), NullWritable.get());
    }
}
